$(function () {
    $("#jqGrid").jqGrid({
        url: '../socialsecuritytransaction/list',
        datatype: "json",
		postData: {"processStatus":"0"},//预申报数据
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true },
			{ label: '单位id', name: 'unitId', index: 'unit_id', width: 80 }, 			
			{ label: '员工id', name: 'employId', index: 'employ_id', width: 80 }, 			
			{ label: '人员派遣id', name: 'personDispatchId', index: 'person_dispatch_id', width: 80 }, 			
			{ label: '申报类型', name: 'declareType', index: 'declare_type', width: 80 }, 			
			{ label: '保险类型', name: 'insuranceType', index: 'insurance_type', editable: true, formatter: getDictInfo},
			{ label: '申报时间', name: 'declareDate', index: 'declare_date', width: 80 }, 			
			{ label: '申报人', name: 'declarePerson', index: 'declare_person', width: 80 }, 			
			{ label: '备注', name: 'remark', index: 'remark', width: 80 }, 			
			{ label: '用工形式', name: 'employmentForm', index: 'employment_form', width: 80 }, 			
			{ label: '异动原因', name: 'transactionReason', index: 'transaction_reason', width: 80 }, 			
			{ label: '初审人', name: 'trialJudge', index: 'trial_judge', width: 80 }, 			
			{ label: '初审日期', name: 'trialDate', index: 'Trial_date', width: 80 }, 			
			{ label: '终审人', name: 'chiefJudge', index: 'chief_judge', width: 80 }, 			
			{ label: '终审日期', name: 'chiefDate', index: 'chief_date', width: 80 }, 			
			{ label: '状态', name: 'state', index: 'state', width: 80 }, 			
			{ label: '退回说明', name: 'returnExplain', index: 'return_explain', width: 80 }			
        ],
		viewrecords: true,
        height: $(window).height()*0.8,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	//$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		socialSecurityTransaction: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		declare: function(){
            var ids = getSelectedRows();
            if(ids == null){
                return ;
            }

            var params = new Object();
            params.type = "process";
            params.operation = "declare";
            params.ids = ids;
            $.ajax({
                type: "POST",
                url: "../socialsecuritytransaction/updateStatus",
                contentType: "application/json",
                data: JSON.stringify(params),
                success: function(r){
                    if(r.code === 0){
                        alert('操作成功', function(index){
                            vm.reload();
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
		},
        unDeclare: function(){
            var ids = getSelectedRows();
            if(ids == null){
                return ;
            }

            var params = new Object();
            params.type = "process";
            params.operation = "unDeclare";
            params.ids = ids;
            $.ajax({
                type: "POST",
                url: "../socialsecuritytransaction/updateStatus",
                contentType: "application/json",
                data: JSON.stringify(params),
                success: function(r){
                    if(r.code === 0){
                        alert('操作成功', function(index){
                            vm.reload();
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        reDeclare: function(){
            var ids = getSelectedRows();
            if(ids == null){
                return ;
            }

            var params = new Object();
            params.type = "process";
            params.operation = "reDeclare";
            params.ids = ids;
            $.ajax({
                type: "POST",
                url: "../socialsecuritytransaction/updateStatus",
                contentType: "application/json",
                data: JSON.stringify(params),
                success: function(r){
                    if(r.code === 0){
                        alert('操作成功', function(index){
                            vm.reload();
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        tempQuit: function(){
            var ids = getSelectedRows();
            if(ids == null){
                return ;
            }

            var params = new Object();
            params.type = "process";
            params.operation = "tempQuit";
            params.ids = ids;
            $.ajax({
                type: "POST",
                url: "../socialsecuritytransaction/updateStatus",
                contentType: "application/json",
                data: JSON.stringify(params),
                success: function(r){
                    if(r.code === 0){
                        alert('操作成功', function(index){
                            vm.reload();
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.socialSecurityTransaction = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.socialSecurityTransaction.id == null ? "../socialsecuritytransaction/save" : "../socialsecuritytransaction/update";
			$.ajax({
				type: "POST",
			    url: url,
			    contentType: "application/json",
			    data: JSON.stringify(vm.socialSecurityTransaction),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../socialsecuritytransaction/delete",
				    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get("../socialsecuritytransaction/info/"+id, function(r){
                vm.socialSecurityTransaction = r.socialSecurityTransaction;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});